package com.wze.wze.Controller;

import com.wze.wze.Aop.PasToken;
import com.wze.wze.Entity.ResultEntity;
import com.wze.wze.Entity.v_love;
import com.wze.wze.Service.v_loveService;
import com.wze.wze.Util.JSONTool;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin //解决跨域
@RestController //控制器注解
@RequestMapping("/vloveMusic/")//请求路径
public class V_loveController {
    @Resource
    v_loveService v_loveService;
    ResultEntity resultEntity = null;


    @PasToken
    @GetMapping("UnLoveMusicList")
    private String LoveMusicList(
            @RequestParam("page") int page,
            @RequestParam("limit") int limit,
            @RequestParam("id")  int id,
            @RequestParam("Uid")  int Uid
    ){
        try {
            resultEntity = new ResultEntity();
            int Start = (page-1) * limit;//计算分页位置
            List<v_love> list = v_loveService.getUnloveMusicList(Start, limit, id, Uid);
            if(id!=-1 || Uid!=-1){//有条件
                resultEntity.setCount(String.valueOf(list.size()));
            }else {//没有查询条件
                resultEntity.setCount(String.valueOf(v_loveService.getloveMusicCount()));
            }
            resultEntity.setCode("0");
            resultEntity.setData(list);
            resultEntity.setMsg("查询成功!");
        }catch (Exception e){
            resultEntity.setCode("1");
            resultEntity.setMsg("查询失败!"+e.getMessage());
        }
        return JSONTool.getJsonTool().toJson(resultEntity);
    }
}
